
<template>
  <el-dialog
    ref="refDlg"
    title="门店建设项目信息"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="800px"
    top="8vh"
    @close="closeDialog"
  >
    <!-- <search-form
      :label-width="150"
      :search-config="searchConfig"
      @search="handleSearch"
    /> -->
    <table-box
      ref="refTable"
      table-size="mini"
      :selected-arry.sync="tableSelected"
      :table-config="tableConfig"
      :table-height="200"
      show-index
      @selection-change="selectionChangeHandle"
    />
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeDialog">关 闭</el-button>
      <el-button :loading="saveLoading" size="mini" type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { saveAutoTask } from '@/api/autoDesignTask'
import { getDictByPatchType } from '@/api/dataDict'
export default {
  name: 'ConstCodeDlg',
  components: { },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    code: {
      type: String,
      default: '',
      require: true
    }
  },
  data() {
    return {
      searchConfig: [
        { label: '门店建设项目号', prop: 'constCode', type: 'text', value: '', placeholder: '' },
        {
          label: '门店',
          prop: 'shopCode',
          type: 'dialog',
          value: '',
          placeholder: '',
          config: {
            requestMethod: 'get',
            remoteUrl: '/select-service/api/v1/shop/page',
            paramField: 'keyWord', // 远程搜索参数名
            defaultProps: {
              label: 'name',
              value: 'code'
            },
            selectData: [],
            filtersRaw: []
          },
          dialogConfig: {
            title: '门店',
            interfacePath: '/select-service/api/v1/shop/page',
            setting: [{ prop: 'code', title: '编码' }, { prop: 'name', title: '名称' }],
            pageFlag: true,
            filtersRaw: []
          }
        },
        {
          label: '客户',
          prop: 'clientCode',
          type: 'dialog',
          value: '',
          placeholder: '',
          config: {
            apiHeader: {
              'permission-code': 'storemanagement',
              'Permission-App': 'slm'
            },
            requestMethod: 'get',
            remoteUrl: '/select-service/api/v1/customer/page',
            paramField: 'keyWord', // 远程搜索参数名
            defaultProps: {
              label: 'name',
              value: 'code'
            },
            selectData: []
          },
          dialogConfig: {
            title: '客户',
            interfacePath: '/select-service/api/v1/customer/page',
            setting: [{ prop: 'code', title: '编码' }, { prop: 'name', title: '名称' }],
            pageFlag: true
          }
        },
        {
          label: '办事处',
          prop: 'officeCode',
          type: 'dialog',
          value: '',
          placeholder: '',
          config: {
            requestMethod: 'get',
            remoteUrl: '/select-service/api/v1/organization/page',
            paramField: 'keyWord', // 远程搜索参数名
            defaultProps: {
              label: 'name',
              value: 'code'
            },
            selectData: []
          },
          dialogConfig: {
            title: '办事处',
            interfacePath: '/select-service/api/v1/organization/page',
            setting: [{ prop: 'code', title: '编码' }, { prop: 'name', title: '名称' }],
            filtersRaw: [{ 'id': 'isOffice', 'property': 'isOffice', 'value': '1', 'operator': '=' }],
            pageFlag: true
          }
        },
        // {
        //   label: '报图类型',
        //   prop: 'marketType',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/MARKET_TYPE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '门店建设类型',
        //   prop: 'constType',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/CONST_TYPE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '商家类别',
        //   prop: 'bizmanType',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/BIZMAN_TYPE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // { label: '门店建设项目号', prop: 'constCode', type: 'text', value: '', placeholder: '' },
        // {
        //   label: '装修范围',
        //   prop: 'decorationRange',
        //   type: 'select',
        //   config: {
        //     multiple: true,
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/DECORATION_RANGE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '装修形式',
        //   prop: 'decorationForm',
        //   type: 'select',
        //   config: {
        //     multiple: true,
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/DECORATION_FORM?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '门店建设整体进度',
        //   prop: 'constSchedule',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/BEFORE_CONST_SCHEDULE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        {
          label: '门店建设状态',
          prop: 'constState',
          type: 'select',
          config: {
            remote: true,
            remoteUrl: `/data-dict/api/v2/dictionary/CONST_STATE?appCode=slm&domainCode=marketing`,
            defaultProps: { label: 'dictName', value: 'dictCode' }
          }
        },
        // {
        //   label: '门店建设所属阶段',
        //   prop: 'belongStage',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/BELONG_STAGE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '门店建设是否完结',
        //   prop: 'isEnd',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/BOOLEANS?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '是否已开业',
        //   prop: 'isOpen',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/BOOLEANS?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        // {
        //   label: '是否测绘',
        //   prop: 'surveyIsFinishMapping',
        //   type: 'select',
        //   config: {
        //     selectData: [
        //       { label: '未完成', value: '0' },
        //       { label: '已完成', value: '1' }
        //     ]
        //   }
        // },
        // { label: '终止时间', prop: 'endTime', type: 'date', value: '' },
        // {
        //   label: '数据来源',
        //   prop: 'dataSource',
        //   type: 'select',
        //   config: {
        //     remote: true,
        //     remoteUrl: `/data-dict/api/v2/dictionary/SHOP_CONSTRUCT_SOURCE?appCode=slm&domainCode=marketing`,
        //     defaultProps: { label: 'dictName', value: 'dictCode' }
        //   }
        // },
        { label: '创建时间', prop: 'createTime', type: 'date', value: '' }
      ],
      saveLoading: false,
      otherFilter: [],
      tableSelected: [],
      decorationRangeList: [],
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/shopConstruct/page`,
        // interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/configExceptionHandle/page`,
        // hideSearchBar: true,
        apiHeader: {
          'Permission-Percode': 'storemanagement',
          'Permission-App': 'slm'
        },
        // pageSize: 20,
        sort: 'createTime',
        order: 'desc',
        setting: [
          {
            prop: 'constCode',
            label: '门店建设项目号',
            minWidth: 150
          },
          {
            prop: 'constSchedule',
            label: '门店建设整体进度',
            minWidth: 150,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BEFORE_CONST_SCHEDULE'
            }
          },
          {
            prop: 'belongStage',
            label: '所属阶段',
            minWidth: 150,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BELONG_STAGE'
            }
          },
          {
            prop: 'constState',
            label: '门店建设状态',
            minWidth: 150,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'CONST_STATE'
            }
          },
          {
            prop: 'officeName',
            label: '办事处',
            minWidth: 130
          },
          {
            prop: 'clientName',
            label: '客户',
            minWidth: 170
          },
          {
            prop: 'shopName',
            label: '门店',
            minWidth: 170
          },
          {
            prop: 'businessStatus',
            label: '门店营业状态',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_BIZ_STATE'
            }
          },
          {
            prop: 'marketType',
            label: '报图类型',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'MARKET_TYPE'
            }
          },
          {
            prop: 'constType',
            label: '门店建设类型',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'CONST_TYPE'
            }
          },
          {
            prop: 'bizmanType',
            label: '商家类别',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BIZMAN_TYPE'
            }
          },
          {
            prop: 'decorationRange',
            label: '装修范围',
            minWidth: 170,
            render: (creat, row) => {
              if (!row.decorationRange) {
                return
              }
              let list = []
              if (typeof (row.decorationRange) === 'string') {
                list = row.decorationRange.split(',')
              } else {
                list = row.decorationRange
              }
              const arr = []
              this.decorationRangeList.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'isHandover',
            label: '是否交接市场',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'surveyIsFinishMapping',
            label: '测绘情况',
            minWidth: 170,
            render: (creat, row) => {
              if (row.surveyIsFinishMapping === 0 || row.surveyIsFinishMapping === '0') {
                return (<span>未测绘</span>)
              }
              return (<span>已测绘</span>)
            }
          },
          {
            prop: 'surveyState',
            label: '测绘进度',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_SURVEY_STATE'
            }
          },
          {
            prop: 'designState',
            label: '设计进度',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_DESIGN_STATE'
            }
          },
          {
            prop: 'haveDecorationTask',
            label: '装修是否完成',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'isOpen',
            label: '是否开业',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'isEnd',
            label: '门店建设是否完结',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'endTime',
            label: '终止时间',
            minWidth: 170
          },
          {
            prop: 'dataSource',
            label: '数据来源',
            minWidth: 170,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_CONSTRUCT_SOURCE'
            }
          },
          {
            prop: 'createTime',
            label: '创建时间',
            type: 'date',
            minWidth: 170
          }
        ]
      }
    }
  },
  async created() {
    await this.getDictByPatchTypeAll(['DECORATION_RANGE']).then(res => {
      this.decorationRangeList = res.DECORATION_RANGE
    })
  },
  methods: {
    handleSearch(data) {
      this.otherFilter = [...data.filtersRaw]
      this.$nextTick(() => {
        this.$refs.refTable.initTableData('')
      })
    },
    // 选中行
    selectionChangeHandle(rows) {
      this.tableSelected = rows
    },
    // 获取数据字典
    async getDictByPatchTypeAll(data) {
      const obj = await getDictByPatchType(data)
        .then(res => {
          return res
        })
      return obj
    },
    handleConfirm() {
      if (!this.singleJudge(this.tableSelected, '门店建设项目号', true)) {
        return
      }
      const data = { constCode: this.tableSelected[0].constCode }
      this.saveLoading = true
      saveAutoTask(data).then(res => {
        if (res.success) {
          this.$message.success('操作成功')
          this.$emit('success')
          this.closeDialog()
        }
      }).catch(() => {
        this.saveLoading = false
      })
    },
    closeDialog() {
      this.saveLoading = false
      this.$emit('update:visible', false)
    }
  }
}
</script>
<style lang='scss' scoped>
/* @import url(); 引入css类 */

</style>
